package com.newlink.building.activities.main.settings.fragments

import android.os.Bundle
import android.text.TextUtils
import android.view.View
import android.widget.Toast
import androidx.lifecycle.ViewModelProvider
import com.newlink.building.R
import com.newlink.building.activities.main.settings.viewmodels.Module_Phone_FeedbackSettingsViewModel
import com.newlink.building.activities.navigateToAboutSettings
import com.newlink.building.databinding.SettingsFeedbackFragmentBinding

/**
 * @Author: Jake
 * @Date: 2023/1/28
 * @Description:
 */
class Module_Phone_FeedbackSettingsFragment : Module_Phone_GenericSettingFragment<SettingsFeedbackFragmentBinding>() {

    private lateinit var mViewModel: Module_Phone_FeedbackSettingsViewModel

    override fun getLayoutId(): Int = R.layout.settings_feedback_fragment

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        mViewModel = ViewModelProvider(this)[Module_Phone_FeedbackSettingsViewModel::class.java]
        binding.apply {
            lifecycleOwner = viewLifecycleOwner
            viewModel = mViewModel

            setBackClickListener {
                goBack()
            }

            setOnFeedbackClick {
                if (TextUtils.isEmpty(feedbackEt.text)) {
                    feedbackEt.error =
                        resources.getString(R.string.feedback_settings_warning_feedback_empty)
                    return@setOnFeedbackClick
                }
                if (TextUtils.isEmpty(contactEt.text)) {
                    contactEt.error =
                        resources.getString(R.string.feedback_settings_warning_feedback_empty)
                    return@setOnFeedbackClick
                }

                val feedbackContent = feedbackEt.text
                val contactContent = contactEt.text

                Toast.makeText(
                    context,
                    "提交的内容是:$feedbackContent , 提交作者:$contactContent",
                    Toast.LENGTH_SHORT
                ).show()

                navigateToAboutSettings()
            }
        }
    }
}
